<script>
import {ref} from "vue";

export default {
  name: 'ChildComponent',
  components: {},
  async setup() {
    let sum = ref(0);
    let p = new Promise((resolve, reject) => {
      setTimeout(() => {
        if (sum.value === 0) {
          resolve('成功的值' + sum.value);
        } else {
          // 如果失败了，调用reject()，指定失败的reason，变为rejected状态。
          reject('失败的值' + sum.value);
        }
      }, 1000);
    });
    await p;
  }
}
</script>

<template>
  <div class="child">
    <h3>我是 Child 组件【子组件】</h3>
    <hr>
    <h2>sum的值是:{{ sum }}</h2>
  </div>
</template>

<style scoped>
.child {
  background: skyblue;
  padding: 20px;
}
</style>